<?php

namespace app\admin\controller;

use app\admin\validate\UserValidate;
use think\Controller;
use think\Db;

class Users extends Controller
{
    //
    public function index()
    {
        if (request()->isAjax()) {
            $data = input('post.');
            $id   = $data['user_id'];
            unset($data['user_id']);
            $ret  = $this->validate($data, UserValidate::class);
            if ($ret !== true) {
                $this->error($ret);
            }
            $result = Db::name('Users')->where('id', $id)->update($data);
            if ($result) {
                $this->success('设置成功', 'admin/users/index');
            } else {
                $this->error('设置失败！稍后重试');
            }
        }
        $userInfo = model('users')->select();
        $viewData = [
            'userInfo' => $userInfo
        ];
        $this->assign($viewData);
        return view();
    }

    //会员删除
    public function delete(){
        $result = Db::name('Users')->where('id',input('post.userID'))->delete();
        if($result){
            $this->success('删除成功',$_SERVER['HTTP_REFERER']);
        }else{
            $this->error('删除失败!',$_SERVER['HTTP_REFERER']);
        }

    }
}
